import request from '@/config/axios'

const baseURL = '/official-website/unit/diy'

export type DiyDetail = {
  id?: string
  diyName: string
  iconUrl: string
  jumpPage: string
  sortNo: number
}

export interface GetDiy extends PageParam {
  diyName?: string
}

// 新增金刚区
export const createDiy = (data: DiyDetail) =>
  request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })

// 根据金刚区id获取金刚区详情
export const getDiyById = (id: string) =>
  request.get<DiyDetail>({
    url: `${baseURL}/get-diy-by-id`,
    params: { id }
  })

// 更改金刚区
export const updateDiy = (data: DiyDetail) =>
  request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })
// 删除金刚区
export const deleteDiy = async (id: string) => {
  return await request.delete<boolean>({
    url: `${baseURL}/delete?id=` + id
  })
}

// 金刚区分页查询
export const getPageDiy = async (data: GetDiy) => {
  return await request.post<PageResult<DiyDetail>>({
    url: `${baseURL}/page`,
    data
  })
}
